<?php
namespace app\course\validate\note;

use think\Validate;

/**
 * 用户验证
 */
class Note extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'type'              => 'require|in:all,my',
        'course_id'         => 'require|integer',
        'course_type'       => 'require|integer|in:1,2,3,4',
        'section_id'        => 'require|integer',
        'content'           => 'require|min:1',
        'open_status'       => 'require|integer|in:0,1',
    ];

    protected $field = [
        'course_id'     => '课程ID',
        'section_id'    => '课时ID',
        'course_type'   => '课程类型',
        'content'       => '笔记',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'type.require'          => '参数错误',
        'type.in'               => '参数错误',
        'course_type.in'        => '课程类型错误',
        'open_status.require'   => '参数错误',
        'open_status.in'        => '参数错误',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'list'      => ['type', 'section_id'],
        'add'       => ['course_id', 'course_type', 'section_id', 'content', 'open_status'],
        'edit'      => ['content', 'open_status'],
    ];

    public function sceneList()
    {
        return $this->only(['phone', 'verify'])->remove('phone', 'unique');
    }
}
